//generator的核心入口

const Generator = require('yeoman-generator');

module.exports = class extends Generator {
    prompting () {
        return this.prompt([
          {
            type: 'input',
            name: 'name',
            message: 'Your project name',
            default: this.appname
          }
        ])
        .then(answers => {
          this.answers = answers
        })
      }

    writing() {
        // 把每一个文件都通过模板转换到目标路径

        const templates = [
            'tsconfig.json',
            'public/robots.txt',
            'public/manifest.json',
            'public/logo512.png',
            'public/logo192.png',
            '.gitignore',
            'package.json',
            'README.md',
            'public/favicon.ico',
            'public/index.html',
            'config/jest/cssTransform.js',
            'config/jest/fileTransform.js',
            'config/env.js',
            'config/getHttpsConfig.js',
            'config/modules.js',
            'config/paths.js',
            'config/pnpTs.js',
            'config/webpack.config.js',
            'config/webpackDevServer.config.js',
            'scripts/build.js',
            'scripts/start.js',
            'scripts/test.js',
            'src/components/App.css',
            'src/components/App.test.tsx',
            'src/components/App.tsx',
            'src/index.css',
            'src/index.tsx',
            'src/logo.svg',
            'src/react-app-env.d.ts',
            'src/reportWebVitals.ts',
            'src/setupTests.ts'
            
        ]

        templates.forEach(item => {
            // item => 每个文件路径
            this.fs.copyTpl(
                this.templatePath(item),
                this.destinationPath(item),
                this.answers
            )
        })
    }
}